#ifndef __TWINS_SPJ_USER_RUN_EVENT_HPP__
#define __TWINS_SPJ_USER_RUN_EVENT_HPP__

#include "base_event.hpp"

namespace run_code_event_space {

struct twins_spj_user_run_event : base_event<twins_spj_user_run_event> {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context, const string& inFile);
};

template <class U>
ProcessStatus twins_spj_user_run_event::execute_impl(run_code_context_t<U>& context, const string& inFile) {
    if (!context.judge_type.spjCompileOk) {
        return ProcessStatus{
                    .result = SPJFILE_COMPILE_ERROR,
                    .error = "spj not ready"
        };
    }

    const RuncodeParams& params = context.params;
    const U& judge_type = context.judge_type;
    auto& [spjLang, spjCodeFile, spjBinFile, spjCompileStr, spjRunStr] = judge_type.spjCodeInfo;
    auto& [userLang, userCodeFile, userBinFile, userCompileStr, userRunStr] = judge_type.userCodeInfo;
    return general_execution_strategy::twins_process_run<true>(
                                        spjLang, spjRunStr, 
                                        userLang, userRunStr, 
                                        params.timeLimit, params.memoryLimit, 
                                        inFile, "",
                                        params.spjCachePath, params.userCachePath);
}

}

#endif /* __TWINS_SPJ_USER_RUN_EVENT_HPP__ */
